*Chapter 1
use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch1StateDoD\setup_historical.dta", clear
keep if year<2003
twoway line defense_spend_96d year || line state_spend_96d year, /*
	*/ title("Defense and State Department") subtitle("Spending in billions of 1996 dollars, 1865-2002") /*
	*/ legend(label (1 "Defense") label(2 "State") rows(1) symxsize(2) size(small)) /*
	*/ xtitle("") xlabel(1865(20)2000, labsize(vsmall))
graph export "01-01_milnertingley_fig.eps", replace cmyk(on) fontface(Times)

use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch1StateDoD\setup_historical.dta", clear
keep if year>1899 & year<2011
twoway line defense_employees year || line state_employees year, /*
	*/ title("Defense and State Department") subtitle("Civilian Employment in thousands, 1900-2010") /*
	*/ legend(label (1 "Defense*") label(2 "State**") rows(1) symxsize(2) size(small)) /*
	*/ xtitle("") xlabel(1900(10)2010, labsize(vsmall)) ytitle("Civilian Employment in 1000s", margin(medsmall) size(small)) ylabel(, labsize(vsmall)) /*
	*/ note(*Prior to 1947 War and Navy Dept; **Before 1916 State Dept only includes DC employees, size(vsmall))
graph export "01-02_milnertingley_fig.eps", replace cmyk(on) fontface(Times)

*Chapter 3

use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch3ftnt29\107thCong.dta", clear
estimates clear
tobit   DistrictAmount_sc highskillpcnt PrezVotePercRepub , ll(0)
est store Amount
probit AnyContract  highskillpcnt PrezVotePercRepub, robust
est store AnyContracts
*esta _all using "USAID_Districts_2001.doc" , title("District Economic Characteristics and USAID Contracts 107th Congress") starlevels(+ 0.10 * 0.05 ** 0.01)  se(%8.2f)  nom nonum nodep nogaps  b(%8.2f)  label brackets  compress replace


*distribution
use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch3ftnt29\103rdCong.dta", clear
estimates clear
foreach var of varlist totd_sc  numcont numcontr {
tobit   `var' highskillpcnt PrezVotePercRepub , ll(0)
est store `var'1
}


 
use  "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch3USAIDContractors\USAIDContractors.dta", clear
local title "title("Number of USAID Contractors Above Mean Contract Amount", size(small)) subtitle("By Contractor Type; 2001", size(small))"
hist coding if coding~=99, xtitle("") `title' xlabel(#13, angle(70) val) discrete percent ytitle(Percent of Contractors)
*graph save "NumberContractorByType.gph", replace

* Congressional Hearings (Table 3.2)
use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch3CongHearings\hearings.dta", clear
tab combwit data if sample == 1 & related_yn == "yes", col nofreq



 use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch3LobbyingRegression\LobbyingData.dta", clear
local restrict "BFDTI==1 & FAagency==1"
estimates clear
xi: probit NotWH Foreign Defense Trade Immigration  i.yrq  , cl(year)
 est store L1
xi: probit NotWH Foreign Defense Trade  Immigration  i.yrq if  BFDTI==1 , cl(year)
 est store L2
xi: probit NotWH Foreign Defense Trade  Immigration  i.yrq if  `restrict', cl(year)
 est store L3

local order "order(Foreign Defense )"
esta *mfx using "LobbyingDataCategories.tex" , fragment  mtitles("L1" "L2" "L3")  `order' addnotes("") title("") starlevels(+ 0.10 * 0.05 ** 0.01)  se drop(_* ) nom nonum nodep nogaps  b(a2)  label brackets  compress replace



*Done in R using stm package
*R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch3LobbyingText
load("DEF7topics.RData")

plotModels(models)
m1<-models$runout[[9]]
prep1 <- estimateEffect( ~ WhiteHouse,m1, meta=meta)

pdf(file="DEF-WHvNOWH.pdf",width=14,height=9)
par(mfrow=c(2,1))
plot(m1,topics=c(1,4,5,6),type="labels",topic.names=c("Research:","Appropriations:","Authorization:","Veterans Health Benefits:"),width=160,main="DEF tagged reports \n \n Topics and High Probability Words")
#plot(m1,type="perspectives",topics=c(6,4))
#title("Topics 4 and 6 Contrast")
#plot(m1,type="perspectives",topics=c(5,1))
#title("Topics 1 and 5 Contrast")
plot.estimateEffect(prep1, "WhiteHouse", model="m1", method="difference",
                    cov.value1=0,cov.value2=1,
                    xlab="Difference in Topic Proportion: Congress Lobbied and WH Bypassed (+) vs WH Lobbied (-)",
                    main="White House Bypass", verbose.labels=F,
                    topics=c(1,4,5,6),labeltype="custom",custom.label=c("Research","Appropriations","Authorization","Veterans Health Benefits")
)
dev.off()



load("TRD10topics.RData")
plotModels(models)
m1<-models$runout[[10]]
prep1 <- estimateEffect( ~ WhiteHouse,m1, meta=meta)

pdf(file="TRD-WHvNOWH.pdf",width=14,height=9)
par(mfrow=c(2,1))
plot(m1,topics=c(3,5,7,9),type="labels",topic.names=c("WTO","Tariffs/Duties","Market Access/Intellectual Property","FTAs"),width=160,main="TRD tagged reports \n \n Topics and High Probability Words")
#plot(m1,type="perspectives",topics=c(9,3))
#title("Topics 3 and 9 Contrast")
#plot(m1,type="perspectives",topics=c(7,5))
#title("Topics 5 and 7 Contrast")
plot.estimateEffect(prep1, "WhiteHouse", model="m1", method="difference",
                    cov.value1=0,cov.value2=1,
                    xlab="Difference in Topic Proportion: Congress Lobbied and WH Bypassed (+) vs WH Lobbied (-)",
                    main="White House Bypass", verbose.labels=F,
                    topics=c(3,5,7,9),labeltype="custom",custom.label=c("WTO","Tariffs/Duties","Intellectual Property/Market Access","FTAs")
)
dev.off()


load("FOR10topics.RData")
plotModels(models)
m1<-models$runout[[10]]
prep1 <- estimateEffect( ~ WhiteHouse,m1, meta=meta)

pdf(file="FOR-WHvNOWH.pdf",width=14,height=9)
par(mfrow=c(2,1))
plot(m1,topics=c(1,2,8,9),type="labels",topic.names=c("Foreign Operations Appropriations","Bilateral Trade Issues","Iranian Sanctions","International Law"),width=160,main="FOR tagged reports \n \n Topics and High Probability Words")
#plot(m1,type="perspectives",topics=c(2,1))
#title("Topics 1 and 2 Contrast")
#plot(m1,type="perspectives",topics=c(9,8))
#title("Topics 8 and 9 Contrast")
plot.estimateEffect(prep1, "WhiteHouse", model="m1", method="difference",
                    cov.value1=0,cov.value2=1,
                    xlab="Difference in Topic Proportion: Congress Lobbied and WH Bypassed (+) vs WH Lobbied (-)",
                    main="White House Bypass", verbose.labels=F,
                    topics=c(1,2,8,9),labeltype="custom",custom.label=c("Foreign Operations Appropriations","Bilateral Trade Issues","Iranian Sanctions","International Law")
)
dev.off()

load("ImmigrationManyTopics.RData")
m1<-models$out[[1]]
prep1 <- estimateEffect( ~ WhiteHouse,m1, meta=meta)

#Use 7 topic
pdf(file="IMM-WHvNOWH.pdf",width=14,height=9)
par(mfrow=c(2,1))
plot(m1,topics=c(1,2,5,6),type="labels",topic.names=c("Visas/Jobs","Overall Reform","Guest Workers","Family/Refugees"),width=160,main="IMM tagged reports \n \n Topics and High Probability Words")
#plot(m1,type="perspectives",topics=c(6,1))
#title("Topics 1 and 6 Contrast")
#plot(m1,type="perspectives",topics=c(5,2))
#title("Topics 2 and 5 Contrast")
plot.estimateEffect(prep1, "WhiteHouse", model="m1", method="difference",
                    cov.value1=0,cov.value2=1,
                    xlab="Difference in Topic Proportion: Congress Lobbied and WH Bypassed (+) vs WH Lobbied (-)",
                    main="White House Bypass", verbose.labels=F,
                    topics=c(1,2,5,6),labeltype="custom",custom.label=c("Visas/Jobs","Overall Reform","Guest Workers","Family/Refugees")
)
dev.off()





*Chapter 4

use  "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch4Budget\BudgetData.dta", clear
local prez "nixon carter reagan bush clinton"
local control "lnunempa  presidentscongressseatshare  rgdpga"
*Table 1, Column 2
xtpcse budsuc def defun unh war dfreal [aweight=appslyf], hetonly
est store B1
*TABLE 1 COLUMN 1
xtpcse budsuc def defun unh war dfreal `prez' [aweight=appslyf], hetonly
est store B2
*drop unified gov interaction
xtpcse budsuc def  unh war dfreal  `prez' [aweight=appslyf], hetonly
est store B3
*Our models
*show that their previous result was mostly due to defense
xtpcse budsuc state  defns_aec    unh war dfreal [aweight=appslyf], hetonly
est store B4
lincom state - defns_aec
xtpcse budsuc state defns_aec   unh war dfreal  `prez' [aweight=appslyf], hetonly
est store B5
lincom state - defns_aec
*adds some additional control variables
xtpcse budsuc state  defns_aec   unh war dfreal `control'   `prez' [aweight=appslyf], hetonly
est store B6
lincom state - defns_aec
xtpcse budsuc state  defns_aec   unh war dfreal `control'   `prez'   Start_mean_Approving2_mos [aweight=appslyf], hetonly
est store B7
lincom state - defns_aec
local order "order(def state defns_aec  )"
esta B*  using "R:\Milner\Milner\MilnerTingleyBook\Results\Budget\BrandiceResults-NoH.tex" , fragment  `order'  starlevels(+ 0.10 * 0.05 ** 0.01)  se drop(`prez'  ) nom nonum nodep nogaps  b(2)  label brackets  compress replace


 
use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch4VoteMargins\VoteMargins.dta", clear
 
reg OwnPartyVoteDiff PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop `c'  , cluster(session)
est store Same1
reg OtherPartyVoteDiff PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop `c'  , cluster(session)
 est store Other1
reg OwnPartyVoteDiff PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop  `c'   if VoteType_Procedural==0, cluster(session)
est store Same2
reg OtherPartyVoteDiff PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop  `c'   if VoteType_Procedural==0, cluster(session)
est store Other2
xi: reg OwnPartyVoteDiff PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop `c'   i.session if VoteType_Procedural==0, cluster(session)
est store Same3
xi: reg OtherPartyVoteDiff PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop `c'   i.session if VoteType_Procedural==0, cluster(session)
est store Other3
xi: reg OwnPartyVoteDiff PrezTriSecurityVsCoop PrezPositionTri SecurityVsCoop  `c2'  i.session if VoteType_Procedural==0, cluster(session)
est store Same4
xi: reg OtherPartyVoteDiff PrezTriSecurityVsCoop PrezPositionTri SecurityVsCoop  `c2'  i.session if VoteType_Procedural==0, cluster(session)
est store Other4
 
local order "order(PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop PrezPositionTri  PrezTriSecurityVsCoop  Security Security_Pres NonSecurity NonSecurity_Pres     )"
local order "order(PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop PrezPositionTri  PrezTriSecurityVsCoop      )"
esta _all using "Rohde-PresSuccess-All.tex" , fragment    `order' addnotes("S1-S5 use President Own Party Yea-Neah as Depenent Variable, S6-S9 uses total Yea-Neah" "All models use OLS with SE's clustered at Congressional Session" "S3, S5 and S8 use session fixed effects (omitted) and S9 uses President FE's" "S1 uses all votes, all other models remove procedural votes" "S4, S5, S8, S9 use trichotomous Presidential position variable") title("House: Influence of Presidential Support and Opposition on Vote Shares") starlevels(+ 0.10 * 0.05 ** 0.01)  se drop(_I*) nom nonum nodep nogaps  b(a3)  label brackets  compress replace


*Create first difference plot

local c "Start_mean_Approving2 PrezPosPopularity "
gen mnval=.
gen se=.
gen upval=.
gen dwval=.
local h=1.65
xi: reg OwnPartyVoteDiff PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop `c'   i.session if VoteType_Procedural==0, cluster(session)
lincom PrezSecurityVsCoop + SecurityVsCoop
replace mnval=r(estimate) if _n==2
replace se=r(se) if _n==2
replace upval=mnval+`h'*se if _n==2
replace dwval=mnval-`h'*se if _n==2
xi: reg OtherPartyVoteDiff PrezPositionYVSN PrezSecurityVsCoop SecurityVsCoop `c'   i.session if VoteType_Procedural==0, cluster(session)
est store Other3
lincom PrezSecurityVsCoop + SecurityVsCoop
replace mnval=r(estimate) if _n==1
replace se=r(se) if _n==1
replace upval=mnval+`h'*se if _n==1
replace dwval=mnval-`h'*se if _n==1

gen index2=_n if _n<3
 label define index2 1 "Other Party" 2 "Own Party" 
label val index2 index2

local c " if index2<3"
twoway (scatter index2 mnval `c', ylabel(1(1)2, valuelabel angle(0))  ytitle("") xtitle("Vote Margin Difference")) ///
(rcap dwval upval index2 `c', hor legend(off) graphregion(margin(t+30 b+30)) xlabel(, valuelabel)  ) 
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\04-01_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace
 graph export "R:\Milner\Milner\MilnerTingleyBook\Results\RollCallVoting\graphs\MarginsFirstDiff2014.pdf", replace
 



use  "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch4RollCallVote\RCVWorking.dta", clear

set matsize 800


foreach id of varlist PrezVotePercRepub  {
estimates clear
local ideo "`id'"
 local u 111
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new    i.VoteID if FECproblems~=1 & FPAid==1 & session>95 & session<`u', pa robust 
mfx2, stub(FPAid)
est store FPAid
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new    i.VoteID if FECproblems~=1 & EconAid==1 & session>95 & session<`u', pa robust 
mfx2, stub(EconAid)
est store EconAid
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new   i.VoteID if FECproblems~=1 & FoodAid==1 & session>95 & session<`u', pa robust 
mfx2, stub(FoodAid)
est store FoodAid
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new    i.VoteID if FECproblems~=1 & Immigration==1 & session>95 & session<`u', pa robust 
mfx2, stub(Imm)
est store Imm
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new    i.VoteID if FECproblems~=1 & Trade==1 & session>95 & session<`u', pa robust 
mfx2, stub(Trade)
est store Trade
xi: xtprobit  rc_vote highskillpcnt  `ideo'   lnsum_contract_dollarval_cd      i.VoteID if FECproblems~=1 & DomDefSpend==1 & session>95 & session<`u', pa robust 
mfx2, stub(DomDef)
est store DomDef
 xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new   i.VoteID if FECproblems~=1 & GeoStrat==1 & session>95 & session<`u', pa robust 
mfx2, stub(GeoStrat)
est store GeoStrat
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new   i.VoteID if FECproblems~=1 & MilitaryDeploy==1 & session>95 & session<`u', pa robust 
mfx2, stub(MilDepl)
est store MilDepl
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new   i.VoteID if FECproblems~=1 & Sanctions==1 & session>95 & session<`u', pa robust 
mfx2, stub(Sanctions)
est store Sanctions

local order "order(PrezSuppSamePty_new highskillpcnt   `ideo'   )"
 
local model1 "mtitles("EconAid"   "Imm"  "Trade" "DomMilSpend" "Sanctions"  "GeoPol" "MilDepl")"
esta EconAid_mfx Imm_mfx Trade_mfx  DomDef_mfx Sanctions_mfx  GeoStrat_mfx MilDepl_mfx using "Table1-House-`ideo'_slim.tex" , fragment `model1' `order' title("House: Panel Probit with Population Average Effects and Vote Fixed Effects (omitted)") starlevels(+ 0.10 * 0.05 ** 0.01)  se drop(_I*) nom nonum nodep nogaps  b(a3)  label brackets  compress replace
 
estimates clear
local ideo "`id'"
local controls2 "bankPACpcntPAC_3_ corpPACpcntPAC_3_ labPACpcntPAC_3_   unemployedpcnt pcntForBorn  Wdummy MWdummy  southdummy pcntBlack"
local u 111
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new  `controls2'   i.VoteID if FECproblems~=1 & FPAid==1 & session>95 & session<`u', pa robust 
mfx2, stub(FPAid)
est store FPAid
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new  `controls2'   i.VoteID if FECproblems~=1 & EconAid==1 & session>95 & session<`u', pa robust 
mfx2, stub(EconAid)
est store EconAid
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new MktValAgProdII `controls2'  i.VoteID if FECproblems~=1 & FoodAid==1 & session>95 & session<`u', pa robust 
mfx2, stub(FoodAid)
est store FoodAid
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new  `controls2'   i.VoteID if FECproblems~=1 & Immigration==1 & session>95 & session<`u', pa robust 
mfx2, stub(Imm)
est store Imm
 xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new  `controls2'   i.VoteID if FECproblems~=1 & Trade==1 & session>95 & session<`u', pa robust 
mfx2, stub(Trade)
est store Trade
 xi: xtprobit  rc_vote highskillpcnt  `ideo'  lnsum_contract_dollarval_cd   `controls2' i.VoteID if FECproblems~=1 & DomDefSpend==1 & session>95 & session<`u', pa robust 
mfx2, stub(DomDef)
est store DomDef
 xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new  `controls2'  i.VoteID if FECproblems~=1 & GeoStrat==1 & session>95 & session<`u', pa robust 
mfx2, stub(GeoStrat)
est store GeoStrat
 xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new  `controls2'  i.VoteID if FECproblems~=1 & MilitaryDeploy==1 & session>95 & session<`u', pa robust 
mfx2, stub(MilDepl)
est store MilDepl
 xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new  `controls2'  i.VoteID if FECproblems~=1 & Sanctions==1 & session>95 & session<`u', pa robust 
mfx2, stub(Sanctions)
est store Sanctions
local order "order(PrezSuppSamePty_new highskillpcnt   `ideo'  `controls2' )"
 
local model1 "mtitles("EconAid"   "Imm"  "Trade" "DomMilSpend" "Sanctions" "GeoPol" "MilDepl")"
esta EconAid_mfx Imm_mfx Trade_mfx DomDef_mfx Sanctions_mfx GeoStrat_mfx MilDepl_mfx using "Table2-House-`ideo'_slim.tex" , fragment `model1' `order' title("House: Panel Probit with Population Average Effects and Vote Fixed Effects (omitted)") starlevels(+ 0.10 * 0.05 ** 0.01)  se drop(_I*) nom nonum nodep nogaps  b(a3)  label brackets  compress replace

 
}


*First difference graph
set scheme  s1mono
set matsize 800

*label define VoteCat 1 "FPAid" 2 "EconAid" 3 "FoodAid" 4 "Immigration" 5 "Trade" 6 "DomDefSpend" 7 "GeoStrat" 8 "MilitaryDeploy"
gen VoteCatSmall=1 if VoteCat==2
replace VoteCatSmall=2 if VoteCat==4
replace VoteCatSmall=3 if VoteCat==5
replace VoteCatSmall=4 if Sanctions==1
replace VoteCatSmall=5 if VoteCat==7
replace VoteCatSmall=6 if VoteCat==8
replace VoteCatSmall=7 if DomDefSpend==1

*President variable
local ideo PrezVotePercRepub
local controls2 "bankPACpcntPAC_3_ corpPACpcntPAC_3_ labPACpcntPAC_3_   unemployedpcnt pcntForBorn  Wdummy MWdummy  southdummy pcntBlack MktValAgProdII"
local region "Wdummy MWdummy  southdummy "
local new ""Economic Aid" "Immigration" "Trade" "Sanctions" "GeoStrategicAid"  "Military Deployment""
local med_ivs "`ideo' `controls2' highskillpcnt"
local wnew: word count `new'
local wmed_ivs: word count `med_ivs'

capture gen upval=.
capture gen dwval=.
capture gen mnval=.
capture gen index=_n
forval a = 1/`wnew' {
di "`a'"
*preserve
local title: word `a' of `new'
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new  `controls2' i.VoteID  if VoteCatSmall==`a' & FECproblems~=1, pa robust
xtprval  PrezSuppSamePty_new , at(0 1) rest(mean)
replace upval=r(_fdhi) if index==`a'
replace dwval=r(_fdlo) if index==`a'
replace mnval=r(_fd) if index==`a'
*restore
}
gen index2=index
label define index2 1 "Economic Aid" 2 "Immigration" 3 "Trade" 4 "Sanctions" 5  "GeoPoliticalAid" 6 "Military Deployment"
label val index2 index2
local c " if index2<=6"
twoway (scatter index2 mnval `c', ylabel(1(1)6, valuelabel angle(0))  ytitle("Vote Type") xtitle("Change in Probability of Pro Vote")) (rcap dwval upval index2 `c', hor legend(off) xlabel(, valuelabel) note("Effect of changing President variable from 0 to 1 holding all other variables at mean" "90% Confidence Intervals"))
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\RollCallVoting\graphs\PrezFirstDiff2014.pdf", replace
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\04-02_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace




*IDEOLOGY
local ideo PrezVotePercRepub
local controls2 "bankPACpcntPAC_3_ corpPACpcntPAC_3_ labPACpcntPAC_3_   unemployedpcnt pcntForBorn  Wdummy MWdummy  southdummy pcntBlack MktValAgProdII"
local region "Wdummy MWdummy  southdummy "
local new ""Economic Aid" "Immigration" "Trade" "Sanctions" "GeoStrategicAid"  "Military Deployment" "Military Spending""
local med_ivs "`ideo' `controls2' highskillpcnt"
local wnew: word count `new'
local wmed_ivs: word count `med_ivs'

capture gen upval=.
capture gen dwval=.
capture gen mnval=.
capture gen index=_n
forval a = 1/`wnew' {
di "`a'"
 
local title: word `a' of `new'
if(`a'!=7){
xi: xtprobit  rc_vote highskillpcnt  `ideo'  PrezSuppSamePty_new  `controls2' i.VoteID  if VoteCatSmall==`a' & FECproblems~=1, pa robust
} 
if(`a'==7){
xi: xtprobit  rc_vote highskillpcnt  `ideo'    `controls2' i.VoteID  if VoteCatSmall==`a' & FECproblems~=1, pa robust
} 
summ `ideo' if VoteCatSmall==`a', d
local l=r(p25)
local h=r(p75)
xtprval  `ideo' , at(`l' `h') rest(mean)
replace upval=r(_fdhi) if index==`a'
replace dwval=r(_fdlo) if index==`a'
replace mnval=r(_fd) if index==`a'
 
}
capture drop index2
gen index2=index
capture label drop index2
label define index2 1 "Economic Aid" 2 "Immigration" 3 "Trade" 4 "Sanctions" 5  "GeoPoliticalAid" 6 "Military Deployment" 7 "Military Spending"
label val index2 index2
local c " if index2<=7"
twoway (scatter index2 mnval `c', ylabel(1(1)7, valuelabel angle(0))  ytitle("Vote Type") xtitle("Change in Probability of Pro Vote")) (rcap dwval upval index2 `c', hor legend(off) xlabel(, valuelabel) note("Effect of changing ideology variable from 25th to 75th percentile" "holding all other variables at mean, with 90% confidence intervals"))
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\RollCallVoting\graphs\IdeoFirstDiff2014.pdf", replace
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\04-03_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace


*Chapter 5

use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch5Bureucracy\BureauData.dta", clear
estimates clear
local i=1
local addl "Start_mean_Approving2 gdp_change"

oprobit count3 externl2  unified  war2 line leg judicial `pres'   `addl' if legbran==0&judbran==0 & NewData!=1, cluster(year)
est store B`i'
local i=`i'+1
*add categories broken out into FP  
oprobit count3 unified  war2 line leg judicial `ag'  `addl' if legbran==0&judbran==0 & NewData!=1, cluster(year)
est store B`i'
local i=`i'+1
oprobit count3 unified  war2 line leg judicial `ag' `pres' `addl' if legbran==0&judbran==0 & NewData!=1, cluster(year)
est store B`i'
local i=`i'+1
*add categories broken out into FP  
oprobit count3 unified  war2 line leg judicial `ag'  `addl' if legbran==0&judbran==0 , cluster(year)
est store B`i'
local i=`i'+1
oprobit count3 unified  war2 line leg judicial `ag' `pres' `addl' if legbran==0&judbran==0 , cluster(year)
est store B`i'
local i=`i'+1
probit  InCab  unified  war2 line leg judicial `ag'  `addl' if legbran==0&judbran==0 , cluster(year)
est store B`i'
local i=`i'+1
probit  InCab  unified  war2 line leg judicial `ag' `pres' `addl' if legbran==0&judbran==0 , cluster(year)
est store B`i'
local i=`i'+1
local order "order(externl2   *FP unified war2 line leg judicial  )"
esta _all using "LewisData.tex" , fragment    `order' addnotes("Bureaucratic Control using Lewis data. ") title("Bureaucratic Control using Lewis et al. data.") starlevels(+ 0.10 * 0.05 ** 0.01)  se drop(`pres' *_cons) nom nonum nodep nogaps  b(2)  label brackets  compress replace

 
*simulated effects
local addl "Start_mean_Approving2 gdp_change"
local pres "truman eisenhow kennedy johnson nixon carter reagan bush clinton bushgw obama"
*local ag "MilFP DiplFP TradeFP AidFP "
local ag "MilFP DomMilSpend DiplFP TradeFP AidFP "
set scheme  s1mono
preserve
capture drop varname prob* valid
capture label drop graphval
oprobit count3 unified  war2 line leg judicial `ag'   `addl' if legbran==0&judbran==0 , cluster(year)
keep if e(sample)
estsimp oprobit count3 unified  war2 line leg judicial `ag'   `addl' if legbran==0&judbran==0 , cluster(year)

setx median
setx  ( `ag' ) 0 (unified  war2 line leg judicial ) 1

gen varname =""
gen problo=.
gen probhi=.
gen probval = .
gen outcome=.
local i = 0
foreach v of varlist `ag' {
forval j=0/4 {

simqi , fd(prval(`j') genpr(prval)) changex(`v' 0 1)
sum prval
replace probval = r(mean) if _n==`++i'
_pctile prval , p(5 95)
replace problo = r(r1) if _n==`i'
replace probhi = r(r2) if _n==`i'
replace varname = "`v'" if _n==`i'
replace outcome = `j' if _n==`i'
drop prval
*label define graphval `i' "`v' (`j')" , modify
label define graphval `i' "`j'" , modify
}
local i = `i'+1
}

gen valid = _n if probval~=.

label val valid graphval
twoway rspike problo probhi valid , horizontal xline(0) || scatter  valid probval , xtitle("Change in probability of Presidential Control") ///
  legend(off) ylabel(1/5 7/11 13/17 19/23 25/29 ,val angle(0) labsize(vsmall)) ytitle("") graphreg(margin(l+18)) text( 3 -.5 "MilFP", size(small)) ///
  text( 9 -.5 "MilSpend", size(small)) text( 15 -.5 "Diplomacy ", size(small)) ///
  text( 21 -.5 "Trade", size(small)) ///
  text( 27 -.5 "Aid", size(small)) 
  graph export "oprobitSimsBureau.pdf", replace
  graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\05-01_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace

restore
 

preserve
capture drop b1- b25
capture drop varname prob* valid
capture label drop graphval
probit  InCab  unified  war2 line leg judicial `ag'   `pres' `addl' if legbran==0&judbran==0 , cluster(year)
estsimp probit  InCab  unified  war2 line leg judicial `ag'  `pres' `addl' if legbran==0&judbran==0 , cluster(year)
 
setx median
setx  (`ag') 0 (unified  war2 line leg judicial ) 1
 
gen varname =""
gen problo=.
gen probhi=.
gen probval = .
local i = 0
foreach v of varlist `ag'  {
simqi , fd(prval(1) genpr(prval)) changex(`v' 0 1)
sum prval
replace probval = r(mean) if _n==`++i'
_pctile prval , p(5 95)
replace problo = r(r1) if _n==`i'
replace probhi = r(r2) if _n==`i'
replace varname = "`v'" if _n==`i'
drop prval
label define graphval `i' "`v'" , modify
}
 
gen valid = _n if probval~=.
label val valid graphval
twoway rspike problo probhi valid , horizontal xline(0) || scatter  valid probval , xtitle("Change in probability of Presidential Control") ylabel(1 "MilFP" 2 "MilSpend" 3 "Diplomacy" 4 "Trade" 5 "Aid") ///
legend(off) ylabel(,val angle(0)) ytitle("")
graph save IncabModel2.gph, replace
graph export probitSimsBureau.pdf, replace 
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\05-02_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace

restore



 use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch5Bureucracy\RespondentWgtPtyLibcon.dta", clear

gen str agcodenew=""
 replace agcodenew="Military" if (agcode=="ARMY"|agcode=="DOD"|agcode=="NAVY"|agcode=="USAF")
replace agcodenew="Non-Military" if (agcode=="USAID"|agcode=="USITC"|agcode=="EXIM"|agcode=="STAT")
 
set scheme s1mono
ciplot libcon7 , by(agcodenew) horiz ytitle("") xtitle("Ideology 7 pt Liberal to Conservative")
graph export agencyideology.pdf, replace




*Chapter 6
 
use"R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch6SurveyInfo\InfoDistrictSurvey.dta", clear
local z "addplot(yscale(r(.2 .8)) xlabel(,angle(90)))"
local t "info_"
 
svyci `t'1 `t'7 `t'3 `t'6 `t'5  `t'8 `t'4, `z' ytitle("% Saying President") title("Who Has Most Information About Use of Tool?")
graph save "infoall.gph", replace
graph export cces13info.pdf, replace
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\06-01_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace  as(eps)

 label var dist_7 "Geopolitical Aid"
label var dist_1 "Mil. Deployment"
local t "dist_"
local z "addplot(yscale(r(.2 .6)) xlabel(,angle(90)))"
svyci `t'1 `t'7 `t'3 `t'6 `t'5 `t'8 `t'4, `z'  title("Who Has Most Information About District Impact?")
graph save "distall.gph", replace
graph export cces13dist.pdf, replace
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\06-02_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace


use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch6WhoControls\Controls.dta", clear
ciplot prezcong_4 prezcong_10 prezcong_6 prezcong_9  prezcong_8 prezcong_11  prezcong_7     , ytitle("% Saying President Controls") title("Who controls policy?") xlabel(,angle(90)) note("")
graph export WhoControls.pdf, replace
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\06-03_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace



use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch6FPReasons\FPReasons.dta", clear
tabout fpreasons1  using tab65.tex , cells(fre col) replace format(0c 1c) clab(Freq %) ptotal(none) oneway style(tex)



use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch6OpinionCovars\TradeImmOpinion.dta", clear

capture drop upval* dwval* mnval*
foreach k of varlist   Ideology {
gen upval`k'=.
gen dwval`k'=.
gen mnval`k'=.
foreach var of varlist ProKoreaTrade ProLegStatus -AntiDenyCitizen {
xi: probit `var' HighSkill Ideology r_gender College4yr SomeCollege HSGrad Age i.state  if weight<=5 [pweight=weight], robust
if("`k'"=="Ideology"){
xtprval  Ideology  , at(0 6) rest(mean)
}
 
replace upval`k'=r(_fdhi) if type=="`var'"
replace dwval`k'=r(_fdlo) if type=="`var'"
replace mnval`k'=r(_fd) if type=="`var'"
}
}



svyset  [pweight=teamweight]
foreach k of varlist   Ideology {
local i=8
foreach var of varlist ProEconAid ProTrade ProMilAid ProUseForce {
 replace type="`var'" if _n==`i'
 xi: reg `var' HighSkill Ideology r_gender College4yr SomeCollege HSGrad Age i.state if teamweight<=5 [pweight=teamweight], robust
replace upval`k'=_b[`k']+invttail(e(N),0.05)*_se[`k'] if type=="`var'"
replace dwval`k'=_b[`k']-invttail(e(N),0.05)*_se[`k'] if type=="`var'"
replace mnval`k'=_b[`k'] if type=="`var'"
local i=`i'+1
}
}


gen index=_n if _n<100


capture label drop index
label define index 1 "ProKoreaTrade" 2 "ProLegStatus" 3 "AntiBorderPatrol" 4 "AntiPoliceQuestion" 5 "AntiFineBiz" 6 "ProHospCare" 7 "AntiDenyCitizen"  8 "ProEconAid" 9 "ProMilAid" 10 "ProUseForce"
label val index index

local c " if index<=7"
foreach k of varlist   Ideology {
twoway (scatter index mnval`k' `c', ylabel(1(1)7, valuelabel angle(0)) title(`k') ytitle("") xtitle("Change in Probability of Preference")) (rcap dwval`k' upval`k' index `c', hor legend(off) xlabel(, valuelabel) note("Effect of change in `k'" "from very Liberal to very Conservative"))
graph save `k'Common.gph, replace
}


local l 8
local h 10
local c " if (index>=`l' & index<=`h')"
foreach k of varlist  Ideology {
twoway (scatter index mnval`k' `c', ylabel(8(1)10, valuelabel angle(0)) title(`k') ytitle("") xtitle("Marginal Effect")) (rcap dwval`k' upval`k' index `c', hor legend(off) xlabel(, valuelabel) note("Effect of change in `k'" "from very Liberal to very Conservative"))
graph save `k'Team.gph, replace
}
foreach k of varlist Ideology    {
graph combine `k'Common.gph `k'Team.gph
graph export FPAttitudesCCES2012_`k'.pdf, replace
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\06-04_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace
}



use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch6CCFR\CCFRData.dta", clear


local f = 1
local z "Gender"
local i "Ideology_sc"
foreach k of varlist  force_index rec_CutExpMilAid rec_CutExpEconAid  {
*reg `k' Ideology `z' i.year, robust
reg `k' `i' `z' i.year , robust

				replace coeff = _b[`i'] if _n == `f'
				replace hi = _b[`i'] + ((invttail(e(df_r), 0.025))*_se[Ideology]) if _n == `f'
				replace lo = _b[`i'] - ((invttail(e(df_r), 0.025))*_se[Ideology]) if _n == `f'
				
	replace dv = "`k'" if _n == `f'				
	local f = `f' + 1
	di "`f'"
}
gen survnum=_n if dv~=""
graph twoway rcap hi lo survnum , horizontal lcolor(navy) || scatter survnum coeff , title("Elite Sample") mcolor(black) msize(small)  ylabel(1 " " 2 " " 3 " ", angle(0)) ytitle("") legend(off) xtitle("Effect of Ideology")
graph save "R:\Milner\Milner\MilnerTingleyBook\Results\PublicOpinion\ChicagoCouncil\IdeologyPooledYears-Elite.gph",replace



use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch6CCFR\CCFRDataMassPublic.dta", clear

local f = 1
local z "Gender College"
local i "Ideology_sc"
foreach k of varlist  force_index rec_CutExpMilAid rec_CutExpEconAid  {
*reg `k' Ideology `z' i.year, robust
reg `k' `i' `z' i.year [pweight=Weight], robust

				replace coeff = _b[`i'] if _n == `f'
				replace hi = _b[`i'] + ((invttail(e(df_r), 0.025))*_se[Ideology]) if _n == `f'
				replace lo = _b[`i'] - ((invttail(e(df_r), 0.025))*_se[Ideology]) if _n == `f'
				
	replace dv = "`k'" if _n == `f'				
	local f = `f' + 1
	di "`f'"
}
gen survnum=_n if dv~=""
graph twoway rcap hi lo survnum , horizontal lcolor(navy) || scatter survnum coeff , title("Public Sample") mcolor(black) msize(small)  ylabel(1 "Mil. Deployment" 2 "Geopolitical Aid" 3 "Economic Aid", angle(0)) ytitle("") legend(off) xtitle("Effect of Ideology")
graph save "R:\Milner\Milner\MilnerTingleyBook\Results\PublicOpinion\ChicagoCouncil\IdeologyPooledYears-Public.gph",replace
graph combine "R:\Milner\Milner\MilnerTingleyBook\Results\PublicOpinion\ChicagoCouncil\IdeologyPooledYears-Public.gph" "R:\Milner\Milner\MilnerTingleyBook\Results\PublicOpinion\ChicagoCouncil\IdeologyPooledYears-Elite.gph" , col(2)
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\PublicOpinion\ChicagoCouncil\IdeologyPooledYears.pdf",replace
graph export "R:\Milner\Milner\MilnerTingleyBook\Results\FinalGraphs\06-05_milnertingley_fig.eps",  fontface(Times) cmyk(on) replace


use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch6PublicConsultation\PublicConsultation.dta", clear


estimates clear
reg pct_med_df Repub Indep [pweight=weight], robust
est store Military1 
reg pct_med_df Repub Indep Male Education Income Age [pweight=weight], robust
est store Military2 
reg pct_med_hum Repub Indep Male [pweight=weight], robust 
est store NonMilitary1
reg pct_med_hum Repub Indep Male Education Income Age [pweight=weight], robust  
est store NonMilitary2
esta _all using "PublicConsultation.tex" , fragment    `order' title("Percentage Budget Cuts by Policy Area") starlevels(+ 0.10 * 0.05 ** 0.01)   se  nom nonum nodep nogaps  b(a3)  label brackets  compress replace

 
* Chapter 7:
use "R:\Milner\Milner\MilnerTingleyBook\Results\ReplicationData\ch7AfricaODA\setup_ssa_oda.dta", clear
keep if year >=1990
graph twoway line aid year, title("U.S. Bilateral ODA Commitments to Sub-Saharan Africa", size(medsmall)) /*
	*/	subtitle("In billions of constant (2009) dollars, 1990-2011", size(small)) /*
	*/	ytitle("Billions of Dollars", size(small)) ylabel(0(2)10, labsize(small)) /*
	*/	xtitle("") xlabel(1990(2)2010, labsize(small))	/*
	*/	note("Source: Geographical Distribution of Financial Flows (OECD, 2012)", size(vsmall))
graph export "07-01_milnertingley_fig.eps", replace cmyk(on) fontface(Times)
